package cn.snowheart.ssm.web;

import cn.snowheart.ssm.service.ITestService;
import cn.snowheart.ssm.util.ResponseUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 测试框架搭好与否
 *
 * @author liuwanxiang
 * @version 2018/4/22
 */
@Controller
public class TestController {

    private Logger logger = Logger.getLogger(TestController.class);

    @Autowired
    private ITestService testService;

    @RequestMapping(value = "/test.json",method = RequestMethod.GET)
    @ResponseBody
    public Object testJson(@RequestParam(value = "name") String name){
        return "Hello " + name;
    }

    @RequestMapping(value = "/test.html",method = RequestMethod.GET)
    public String testHtml(){
        return "/hello";
    }

    @RequestMapping(value = "/test/insert/{count}",method = RequestMethod.GET)
    @ResponseBody
    public Object testInsert(@PathVariable Integer count){
        long start = System.currentTimeMillis();
        logger.info(">>> 进入Servire时间: " + start);
        testService.insertPerson(count);
        long end = System.currentTimeMillis();
        logger.info(">>> 出来Servire时间: " + end + " 耗时: " + (start - end));
        return ResponseUtil.success();
    }

    @RequestMapping(value = "/test/insert/thread/{count}",method = RequestMethod.GET)
    @ResponseBody
    public Object testInsertWithThread(@PathVariable Integer count) throws InterruptedException {
        long start = System.currentTimeMillis();
        logger.info(">>> 进入Servire时间: " + start);
        testService.insertPersonWithThread(count);
        long end = System.currentTimeMillis();
        logger.info(">>> 出来Servire时间: " + end + " 耗时: " + (start - end));
        return ResponseUtil.success();
    }

}